﻿/**
 * ...
 * @author waneck
 */

package asc.events;

enum StreamStatus 
{
	//A call to application.clearStreams() failed to delete a stream.
	StreamClearFailed(streamName:String, ?description:String);
	//A call to application.clearStreams() successfully deleted a stream.
	StreamClearSuccess(streamName:String, ?description:String);
	//An attempt to use a Stream method failed.
	StreamFailed(streamName:String, ?description:String);
	//An call to Stream.play() failed.
	StreamPlayFailed(streamName:String, ?description:String);
	//Data is playing behind the normal speed
	StreamPlaynsufficientBW(streamName:String, ?description:String);
	//Play was started.
	StreamPlayStart(streamName:String, ?description:String);
	//An attempt was made to play a stream that does not exist.
	StreamPlayStreamNotFound(streamName:String, ?description:String);
	//Play was stopped.
	StreamPlayStop(streamName:String, ?description:String);
	//A playlist was reset.
	StreamPlayReset(streamName:String, ?description:String);
	//The initial publish operation to a stream was successful. This message is sent to all subscribers.
	StreamPlayPublishNotify(streamName:String, ?description:String);
	//An unpublish operation from a stream was successful. This message is sent to all subscribers.
	StreamPlayUnpublishNotify(streamName:String, ?description:String);
	//An attempt was made to publish a stream that is already being published by someone else.
	StreamPublishBadName(streamName:String, ?description:String);
	//Publishing was started.
	StreamPublishStart(streamName:String, ?description:String);
	//An attempt to record a stream failed.
	StreamRecordFailed(streamName:String, ?description:String);
	//An attempt was made to record a read-only stream.
	StreamRecordNoAccess(streamName:String, ?description:String);
	//Recording was started.
	StreamRecordStart(streamName:String, ?description:String);
	//Recording was stopped.
	StreamRecordStop(streamName:String, ?description:String);
	//A stream has stopped publishing.
	StreamUnpublishSuccess(streamName:String, ?description:String);
	
	
	StreamOther(level:String, code:String, streamName:String, ?description:String);
}

class StreamStatusTranslator
{
	public static function translate(infoObject: { code:String, description:String, details:String, level:String } ):StreamStatus
	{
		return switch (infoObject.code)
		{
			case "NetStream.Clear.Failed":
				StreamClearFailed(infoObject.details, infoObject.description);
			case "NetStream.Clear.Success":
				StreamClearSuccess(infoObject.details, infoObject.description);
			case "NetStream.Failed":
				StreamFailed(infoObject.details, infoObject.description);
			case "NetStream.Play.Failed":
				StreamPlayFailed(infoObject.details, infoObject.description);
			case "NetStream.Play.InsufficientBW":
				StreamPlaynsufficientBW(infoObject.details, infoObject.description);
			case "NetStream.Play.Start":
				StreamPlayStart(infoObject.details, infoObject.description);
			case "NetStream.Play.StreamNotFound":
				StreamPlayStreamNotFound(infoObject.details, infoObject.description);
			case "NetStream.Play.Stop":
				StreamPlayStop(infoObject.details, infoObject.description);
			case "NetStream.Play.Reset":
				StreamPlayReset(infoObject.details, infoObject.description);
			case "NetStream.Play.PublishNotify":
				StreamPlayPublishNotify(infoObject.details, infoObject.description);
			case "NetStream.Play.UnpublishNotify":
				StreamPlayUnpublishNotify(infoObject.details, infoObject.description);
			case "NetStream.Publish.BadName":
				StreamPublishBadName(infoObject.details, infoObject.description);
			case "NetStream.Publish.Start":
				StreamPublishStart(infoObject.details, infoObject.description);
			case "NetStream.Record.Failed":
				StreamRecordFailed(infoObject.details, infoObject.description);
			case "NetStream.Record.NoAccess":
				StreamRecordNoAccess(infoObject.details, infoObject.description);
			case "NetStream.Record.Start":
				StreamPublishStart(infoObject.details, infoObject.description);
			case "NetStream.Record.Stop":
				StreamRecordStop(infoObject.details, infoObject.description);
			case "NetStream.Unpublish.Success":
				StreamUnpublishSuccess(infoObject.details, infoObject.description);
			default:
				StreamOther(infoObject.level, infoObject.code, infoObject.details, infoObject.description);
		}
	}

}